-- call_building
-- Created by cheny3 Sep/19/2016
-- 技能: 召出建筑

return {
    apply = function(source, target, skillId, round, para, extra)
        if source.type ~= OBJECT_TYPE_MONSTER then
            return {};
        end

        local dungeonId = DungeonM.getDungeonId();
        local classId = para[1];
        local elements = (DungeonM.getElementsByDungeon(dungeonId) or {})[classId];
        if not elements then
            -- 没有元素集合
            return;
        end

        local elementId = elements[1]["id"];
        if not elementId then
            -- 没有元素
            return;
        end

        local pos = source:getPos();
        -- 如果怪物没死，就随机找一个空格
        if not source:isDead() then
            local list = DungeonM.findEmptyGrids();
            if #list <= 0 then
                -- 没有空格
                return {};
            end

            local seed = DungeonM.getRandSeed("fetch_building_pos");
            local index = seed % #list + 1;    -- 客户端下标多1
            pos = list[index];
        end

        -- 召唤
        DungeonM.transformGrid(classId, pos, GRID_STATE_OPEN, {["element"] = elementId});

        return { source, };
    end,

    check = function(skillId, para)
        return true;
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return  { tonumber(arr[1]) };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        return desc;
    end,
}

